﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using ECCIT;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.Mobile;
using OgilvyOne.UKNow.Mobile.Model.Events;
using ECCIT.Extension.Weibo_v2.Common;
using OgilvyOne.UKNow.Mobile.Utilities;
namespace OgilvyOne.UKNow.Mobile.APIs.Events
{

    public class Like : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string sUid = context.Request.Params["uid"];
                string sEid = context.Request.Params["eventid"];
                if (string.IsNullOrEmpty(sUid)) throw new ArgumentNullException("uid");
                if (string.IsNullOrEmpty(sEid)) throw new ArgumentNullException("eventid");

                int uid = int.Parse(sUid);
                int eid = int.Parse(sEid);
                var memmodel = new MemberBLL(2052).getMemberByID((int)uid);
                var emodel = new EventsBLL(2052).selEvent((int)eid);
                if (memmodel != null && emodel != null)
                {
                    uidlike(uid, eid, context);
                }
                else
                {
                    context.Response.Write(ResultUtility.ReturnResultJson("-300", "", "不存在该用户或活动"));
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ResultUtility.ReturnResultJson("-300", "", "用户收藏动失败. Message:" + ex.Message));
            }
           
        }
        private void uidlike(int uid,int eid,HttpContext context) 
        {
            EventCalendarBLL ecbll = new EventCalendarBLL(2052);
            EventCalendarModel ecm = new EventCalendarModel(uid, eid, 2052);
            ResultInfo result= ecbll.Save(ecm);
            if (result.Result)
            {
                UserEvent ue = new UserEvent();
                ue.Uid = ecm.MEMBER_ID.ToString();
                ue.Eventid = ecm.COL_EVENTS_ID.ToString();
                string s = JsonSerializationHelper.ObjectToJson(ue);
                context.Response.Write(ResultUtility.ReturnResultJson("0", s, "用户收藏活动成功"));
            }
            else
            {
                context.Response.Write(ResultUtility.ReturnResultJson("-301", "", "用户已收藏过该活动"));
            }
        }
    }
}
